package com.hym.myobserve;

/**
 * 间谍程序，监控程序是一个线程类
 * */
public class Spy extends Thread {
	private HanFeiZi hanFeiZi;
	private LiSi liSi;
	private String type;
	/**通过构造函数，构造谁被观察，观察谁，观察什么*/
	public Spy(HanFeiZi hanFeiZi,LiSi liSi,String type){
		this.hanFeiZi=hanFeiZi;
		this.liSi=liSi;
		this.type=type;
	}
	
	@Override
	public void run() {
		//用死循环来保证程序一直在监控状态
		while(true){
			//监控是否在吃早餐
			if(this.type.equals("breakfast")){
				if(hanFeiZi.isHaveBreakfast()){
					this.liSi.update("韩非子在吃饭");
					this.hanFeiZi.setHaveBreakfast(false);
				}
			}else{//监控是否在娱乐
				if(hanFeiZi.isHaveFun()){
					this.liSi.update("韩非子在娱乐");
					this.hanFeiZi.setHaveFun(false);
				}
			}
		}
	}
}
